package net.xinqushi.pthread.pthread;

/**
 * X线程 join Y线程，导致X线程优先于 Y线程执行
 * 原理 : 调用join时 使得Y线程阻塞，阻塞到Y线程 is not alive结束
 */
public class ThreadJoin {

    public static void main(String[] args) {
        Thread joinThread = new Thread(()->{
            System.out.println(Thread.currentThread() + " will die ");
        });
        joinThread.start();
        try {
            joinThread.join(); //join
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread() + " will die");
    }
}
